package dto.app;

import dto.api.ApiInfoDto;
import models.application.AniApp;
import models.user.AniUser;
import services.api.AniApiService;

import java.util.List;

/**
 * User: yeh
 * Date: 2/2/13
 * Time: 6:13 PM
 * For:  wilddragon
 */
public class AppInfoDto {

    public Boolean isInstalled;

    public Boolean isActivated;

    public Boolean canInstall;

    public Boolean canModify;

    public List<ApiInfoDto> containedApi;

    private AniApp hostApp;

    public String forwardUrl;

    public AppInfoDto(){}

    public AppInfoDto(AniApp oneAppDao, AniUser oneUser, Boolean isInstalled){
        this.isInstalled = isInstalled;
        Boolean isActivated = oneAppDao.state.id == 1L;
        this.isActivated = isActivated;
        this.canInstall = isActivated && oneAppDao.type.id == 1L;
        this.canModify = oneAppDao.ownerUser.id == oneUser.id;
        this.hostApp = oneAppDao;
        this.forwardUrl = oneAppDao.forwardUrl;
    }

    public AppInfoDto(Boolean installed, Boolean activated, Boolean canInstall, Boolean canModify, String forwardUrl) {
        isInstalled = installed;
        isActivated = activated;
        this.canInstall = canInstall;
        this.canModify = canModify;
        this.forwardUrl = forwardUrl;
    }
    public void setApiInfoList(){
        this.containedApi = AniApiService.getApiDtoListWithAppEntity(this.hostApp);
    }
}
